package infraestructura;

import java.util.ArrayList;
import java.util.List;
import modelo.Comment;

public class CommentMemoryPersistence implements CommentPersistence {

    private List<Comment> comments = new ArrayList();
    private static CommentMemoryPersistence persistence = null;
    
    private CommentMemoryPersistence() {        
        comments.add(new Comment(1, "Mu chulo!!"));
    }
    
    public static CommentPersistence getPersistenceManager() {
        if (persistence == null) {
            persistence = new CommentMemoryPersistence();
        }
        return persistence;
    }

    @Override
    public void addComment(Comment comment) {
        comments.add(comment);
    }

    @Override
    public List<Comment> getCommentsForProduct(int productId) {
        List<Comment> commentsForProduct = new ArrayList();
        for (Comment comment : comments) {
            if (comment.getProductId() == productId) {
                commentsForProduct.add(comment);
            }
        }
        return commentsForProduct;
    }
    
}